var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_RewardUI = /* */function (_cc$Component61) {
  babel_inherits(g, _cc$Component61);
  var _super77 = babel_createSuper(g);
  function g() {
    var _this173;
    babel_classCallCheck(this, g);
    _this173 = _super77.apply(this, arguments);
    _this173.rewardArr = [];
    _this173.index = 0;
    return _this173;
  }
  babel_createClass(g, [{
    key: "onLoad",
    value: function onLoad() {}
  }, {
    key: "init",
    value: function init() {
      Adv_skd.default.instance.hideAllAdv();
      Adv_skd.default.instance.showInterstitialAd();
      Adv_skd.default.instance.showGridAdLeft();
      Adv_skd.default.instance.showGridAdRight();
                    
      var _this174 = this;
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      this.rewardArr = e;
      if (1 == e.length) {
        this.showSingle();
        this.node.getChildByName("CloseBtn").active = true;
        this.node.getChildByName("RewardSingle").getChildByName("NextBtn").active = false;
        this.node.getChildByName("RewardSingle").getChildByName("AllBtn").active = false;
      } else {
        this.showSingle();
        this.node.getChildByName("CloseBtn").active = false;
        if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p1")) {
          this.node.getChildByName("RewardSingle").getChildByName("NextBtn").active = false, this.scheduleOnce(function () {
            _this174.node.getChildByName("RewardSingle").getChildByName("NextBtn").active = true;
          }, $2pvzChannel.pvzChannel.instance().getCtrl("p1"));
        } else {
          this.node.getChildByName("RewardSingle").getChildByName("NextBtn").active = true;
        }
        if (3 == e.length) {
          this.node.getChildByName("RewardSingle").getChildByName("AllBtn").active = false;
        } else {
          this.node.getChildByName("RewardSingle").getChildByName("AllBtn").active = true;
        }
      }
    }
  }, {
    key: "showAll",
    value: function showAll() {
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
        $2ADManager.default.instance.hideNative(2);
        $2ADManager.default.instance.hideNative(3);
      }
      this.node.getChildByName("RewardSingle").active = false;
      this.node.getChildByName("RewardList").active = true;
      this.node.getChildByName("CloseBtn").active = true;
      for (var _e83 = 0; _e83 < this.rewardArr.length; _e83++) {
        var _t55 = this.rewardArr[_e83];
        if ("a" == _t55.rewardType) {
          this.node.getChildByName("RewardList").children[_e83].getChildByName("Chip").active = true;
          this.node.getChildByName("RewardList").children[_e83].getChildByName("Num").active = true;
          this.node.getChildByName("RewardList").children[_e83].getChildByName("Num").getComponent(cc.Label).string = "X" + _t55.number;
        } else {
          this.node.getChildByName("RewardList").children[_e83].getChildByName("Chip").active = false;
          this.node.getChildByName("RewardList").children[_e83].getChildByName("Num").active = false;
        }
        this.node.getChildByName("RewardList").children[_e83].getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + _t55.plantID, cc.SpriteFrame);
        this.node.getChildByName("RewardList").children[_e83].getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/s" + _t55.rare, cc.SpriteFrame);
      }
    }
  }, {
    key: "showSingle",
    value: function showSingle() {
      var _this175 = this;
      this.node.getChildByName("RewardSingle").active = true;
      var e = this.rewardArr[this.index];
      if (e) {
        if ("a" == e.rewardType) {
          this.node.getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
          this.node.getChildByName("RewardSingle").getChildByName("Chip").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("Num").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("PlantAni").active = false;
          this.node.getChildByName("RewardSingle").getChildByName("Bg").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + e.number;
          this.node.getChildByName("RewardSingle").getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/s" + e.rare, cc.SpriteFrame);
          this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + e.plantID, cc.SpriteFrame);
        } else if ("b" == e.rewardType) {
          if ($2UserDataManager.default.instance.plantLock.includes(e.plantID) && !$2DataManager.default.instance.newPlant.includes(e.plantID)) {
            this.node.getChildByName("RewardSingle").getChildByName("TipLabel").active = true;
          } else {
            this.node.getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
          }
          this.node.getChildByName("RewardSingle").getChildByName("Chip").active = false;
          if (1 != e.number) {
            this.node.getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + e.number;
          } else {
            this.node.getChildByName("RewardSingle").getChildByName("Num").active = false;
          }
          this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").active = false;
          this.node.getChildByName("RewardSingle").getChildByName("PlantAni").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("Bg").active = false;
          if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName, sp.SkeletonData)) {
            this.node.getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName, sp.SkeletonData), this.node.getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
          } else {
            $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName, sp.SkeletonData, function () {
              _this175.node.getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName + "/" + $2PlantMgr.default.instance().getPlant(e.plantID).dragonName, sp.SkeletonData);
              _this175.node.getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
            });
          }
        } else {
          this.node.getChildByName("RewardSingle").getChildByName("Chip").active = false;
          this.node.getChildByName("RewardSingle").getChildByName("PlantAni").active = false;
          this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("Num").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("Bg").active = true;
          this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").scale = 1;
          this.node.getChildByName("RewardSingle").getChildByName("Num").getComponent(cc.Label).string = "X" + e.number;
          this.node.getChildByName("RewardSingle").getChildByName("TipLabel").active = false;
          if (1 == e.rare) {
            this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
          } else {
            this.node.getChildByName("RewardSingle").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
          }
        }
      } else {
        this.onClickClose();
      }
    }
  }, {
    key: "onClickNextBtn",
    value: function onClickNextBtn() {
      if (this.index >= 9) {
        this.showAll();
      } else {
        this.index++;
        this.showSingle();
      }
    }
  }, {
    key: "onClickClose",
    value: function onClickClose() {
      Adv_skd.default.instance.hideAllAdv();

      $2DataManager.default.instance.drawGuide && $2UIManager.default.instance.uiList.GuideUI2 && $2UIManager.default.instance.uiList.GuideUI2.emit("nextStep");
      $2UIManager.default.instance.closeUI("RewardUI");
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
        $2ADManager.default.instance.hideNative(2);
        $2ADManager.default.instance.hideNative(3);
      }
    }
  }]);
  return g;
}(cc.Component);
def_RewardUI = cc__decorate([ccp_ccclass], def_RewardUI);
exports.default = def_RewardUI;